﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using TiaoTiaoCode.AutoUpdate.ClientUI.Enums;

namespace TiaoTiaoCode.AutoUpdate.ClientUI.Converts
{
    /// <summary>
    /// 文件状态转图标颜色
    /// </summary>
    [ValueConversion(typeof(FileUpgradeState), typeof(SolidColorBrush))]
    public class FileUpgradeStateToColorConverter : IValueConverter
    {
        /// <summary>
        /// 状态转颜色
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is FileUpgradeState state)) return new SolidColorBrush(Colors.Black);

            return new SolidColorBrush(state switch
            {
                FileUpgradeState.Wait => Colors.Black,
                FileUpgradeState.Downloading => Colors.Yellow,
                FileUpgradeState.Completed => Colors.Green,
                FileUpgradeState.Error => Colors.Red,
                _ => Colors.Black
            });
        }

        /// <summary>
        /// 颜色转状态
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return default!;
        }
    }
}
